home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 726 < prev    next >
Text File  |  1996-08-06  |  2KB  |  40 lines

  1. Newsgroups: comp.std.c
  2. Path: news.uunet.ca!wildcan!sq!msb
  3. From: msb@sq.com (Mark Brader)
  4. Subject: Re: Restrictions on qsort compare function?
  5. Message-ID: <1996Apr12.072210.10442@sq.com>
  6. Organization: SoftQuad Inc., Toronto, Canada
  7. References: <4kbl1l$74r@sam.inforamp.net> <829068682snz@genesis.demon.co.uk> <Dpo6Cs.CG0@stdc.demon.co.uk>
  8. Date: Fri, 12 Apr 1996 07:22:10 GMT
  9.  
  10. Lawrence Kirby  <fred@genesis.demon.co.uk> wrote:
  11. > > In all of your examples
  12. > > the behaviour can vary depending on the actual implementation of qsort().
  13. > > In the absense of any other limitation in the standard (such as a statement
  14. > > of implementation-defined behaviour), this means the behaviour is undefined.
  15.  
  16. Clive Feather (cdwf@cityscape.co.uk) writes:
  17. > No, this is circular logic.  A library function must be inferred to do
  18. > only what its specification says, and nothing else; you can't use
  19. > undescribed behaviour to deduce that a specific call to that function
  20. > is undefined.
  21.  
  22. Sorry, Clive, but that doesn't wash; Lawrence is right.  Before you can
  23. say that a library function does "only what its specification says", that
  24. specification has to be meaningful.  Well, this particular library function
  25. is specified as sorting "according to [the] comparison function".  Since
  26. the sequence and timing of the calls that qsort() makes to the comparison
  27. function is not specified, it follows that the specification of qsort()
  28. is meaningful only if it is independent of that sequence and timing.
  29. If it ISN'T indedependent, the behavior of qsort() is undefined.
  30.  
  31. (Similarly, if the comparison function returns inconsistent values --
  32. if it is nontransitive or non-antisymmetric -- again it is not meaningful
  33. to sort "according to" it.  So the behavior is undefined there also.)
  34. -- 
  35. Mark Brader              |  ...the scariest words of the afternoon:
  36. msb@sq.com               |   "Hey, don't worry, I've read all about
  37. SoftQuad Inc., Toronto   |    doing this sort of thing!"    -- Vernor Vinge
  38.  
  39. My text in this article is in the public domain.
  40.